﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using KqAutoDesign.Base;

namespace KqAutoDesign.SonViews
{
    /// <summary>
    /// ModuleCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class ModuleCtrl : UserControl
    {
        public ModuleCtrl()
        {
            InitializeComponent();
        }

        public ModuleCtrl(ModuleCtrlVM vm):this()
        {
            DataContext = vm;
        }

        public event Action<int> ModuleClicked;

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if(DataContext is ModuleCtrlVM vm)
            {
                ModuleClicked?.Invoke(vm.Id);
            }
        }
    }

    public class ModuleCtrlVM:NotifyBase
    {
        private Image _img;
        public Image Img
        {
            get { return _img; }
            set
            {
                if (_img != value)
                {
                    _img = value;
                    OnPropertyChanged(nameof(Img));
                }
            }
        }

        private string _name;
        public string ModuleName
        {
            get { return _name; }
            set
            {
                if (_name != value)
                { 
                    _name = value;
                    OnPropertyChanged($"{nameof(ModuleName)}");  
                }
            }
        }

        private int _id;
        public int Id
        {
            get { return _id; }
            set
            {
                if ( _id != value)
                {
                    _id = value;
                    OnPropertyChanged(nameof(Id));
                }
            }
        }
    }
}
